package org.example.day20240820;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main1 {
//            4
//            3310120150912233 2 4
//            3310120150912119 4 1
//            3310120150912126 1 3
//            3310120150912002 3 2
//            2
//            3 4
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        scanner.nextLine();
        List<Stu_Info> list = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            String str = scanner.nextLine();
            String[] arr = str.split(" ");
            Stu_Info stuInfo = new Stu_Info(arr[0], arr[1], arr[2]);
            list.add(stuInfo);
        }
        scanner.nextLine();
        String noStr = scanner.nextLine();
        String[] noArr = noStr.split(" ");
        for (int i = 0; i < noArr.length; i++) {
            String strTrySeatNo = noArr[i];
            for (Stu_Info stuInfo : list) {
                if (strTrySeatNo.equals(stuInfo.try_seat_no)) {
                    System.out.println(stuInfo.no + " " + stuInfo.exam_seat_no);
                }
            }
        }
    }


}
